03. Flask-Migrate - Part 1

Flask-Migrate Heading

Flask-Migrate

We want to allow the user to check or uncheck todo items in our Todo app, to mark them as completed or not. Right now, we don't have a concept of what "completed" means in our database, which models a Todo with a single property called "description". We'd like to extend the model to also include a boolean property called "completed" in order to allow for todos to be marked as completed or not by a user on our app.

While we can do this totally using psql or another Postgres client to simply alter our table to add a new column using the ALTER TABLE ADD COLUMN command in SQL, we should use migrations to handle changes to our database schema for better maintainability and the ability to rollback quickly in case of issues.

Over the next few pages, we'll walk through how to use Flask-Migrate to add a new completed column to our to-do model.

Installing Flask-Migrate and Using the Documentation

ND004 C01 L06 03 Flask-Migrate

00:00
00:00

Task Description:

Have the documentation available as you work. Links:

Next, install Flask-Migrate by running:

pip3 install Flask-Migrate
Task List:

Task Feedback:

Good—then let's get started!

Importing the Migrate library and creating an instance of the Migrate class

ND004 C01 L06 03.1 Flask-Migrate

00:00
00:00

Follow along! Interactive Workspace

  • Install Flask-Migrate
  • Instantiate migrate

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: jupyter-lab
  • Opened files (when workspace is loaded): n/a